<!DOCTYPE html>
<html class="ui-page-login">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>用户注册</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<style>
			.code{
				color:#757575;
			}
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<span class="mui-action-back mui-icon mui-icon-arrowleft"></span>
		    <h1 class="mui-title">注册</h1>
		    <a id='logs' class="mui-pull-right">登录</a>
		</header>
		<div class="mui-content">
			<form class="mui-input-group register">
				<div class="mui-input-row first">
					<input id='account' type="text" class="mui-input-clear mui-input" placeholder="请输入您的手机号">
				</div>
				<div class="mui-input-row code">
			        <input type="text"  placeholder="请输入验证码" id="u_code">
			        <b></b>
					<a href="javascript:senmobile(60);" id="get_code" disabled="true">获取验证码</a>
			    </div>
				<div class="mui-input-row">
					<input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
				</div>
				<div class="mui-input-row">
					<input id='repwd' type="password" class="mui-input-clear mui-input" placeholder="请再次输入密码">
				</div>
			</form>
			<div class="mui-content-padded">
				<button id='reg' class="mui-btn mui-btn-block mui-btn-primary reg">提交</button>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/app.js"></script>
		<script src="js/configs.js"></script>
		<script src='libs/easymob-webim-sdk/jquery-1.11.1.js'></script>
		<script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.js"></script>
		<script >jQuery.noConflict()</script>
		<script>
			var password_reg = /^[a-zA-Z0-9\d+]{6,20}$/;
			var reg =/^[1][3,4,5,7,8,]\d{9}$/;
			var issend=true;  
			function senmobile(t){  
			     if(issend){  
			    //验证电话号码手机号码  
			    var phoneObj = document.getElementById('account');  
			    var pw = document.getElementById('password');  
			    var repw = document.getElementById('repwd'); 
			    var get_code=document.getElementById('get_code');  
			    if (phoneObj.value != ""){   
			        var phoneVal=phoneObj.value; 
			        var reg =/^[1][3,4,5,7,8,]\d{9}$/;
			        //var p1 = /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;   
			        var me = false;   
			        if (reg.test(phoneVal)) me=true;   
			        if (!me){   
			            phoneObj.value='';   
			            mui.toast('请输入正确的手机号码');  
			            phoneObj.focus();   
			            return false;   
			        }else{  
			            //alert(1);
			            var a=phoneObj.value;
			            issend=false; 
			           	mui.ajax({  
			                  url:server.stockCode+a,  
			                  dataType:"json",  
			                  type:"POST",  
			                  success:function(data){  
			                        if(data.code == 0){
			                        	mui.toast('验证码发送成功')
			                        }else{
			                        	mui.toast('验证码发送失败')
			                        }
			                        for(i=1;i<=t;i++) {   
			                            window.setTimeout("update_a(" + i + ","+t+")", i * 1000);   
			                        }   
			                  }  
			            }); 
			              
			        }  
			    }else{  
			    	mui.toast('手机号码不能为空')
			        return false;  
			    }  
			}  
			}  
			function update_a(num,t) {   
			    var get_code=document.getElementById('get_code');  
			    if(num == t) {   
			        get_code.innerHTML =" 重新发送 ";   
			        issend=true;   
			    }   
			    else {   
			       var printnr = t-num;   
			        get_code.innerHTML =printnr +" 秒后重发";   
			    }   
			} 
			document.getElementById("reg").addEventListener('tap',function(){
		            	  //验证电话号码手机号码  
			    var phoneObj = document.getElementById('account');  
			    var pw = document.getElementById('password');  
			    var repw = document.getElementById('repwd'); 
			    var get_code=document.getElementById('u_code'); 
			    var phoneVal=phoneObj.value; 
			    var pwVal=pw.value; 
			    var codeVal=get_code.value;
			    var repwVal = repw.value;
			    if(!phoneVal||!reg.test(phoneVal)){
			    	mui.toast('请输入正确的手机号');return false;	
			    }else if(!codeVal){
			    	mui.toast('请输入验证码');return false;	
			    }else if(!pwVal||pwVal.length>16||pwVal.length<6){
			    	mui.toast('请输入正确的密码');return false;	
			    }else if(repwVal!=pwVal){
			    	mui.toast('两次密码输入不一致');return false;
			    }else{
			    	jQuery.ajax({
			    		type:'post',
			    		url:server.stockReg,
			    		data:{
			    			account:phoneVal,
		                    code:codeVal,
		                    pswd:md5(pwVal)
			    		},
			    		dataType:'json',
			    		success:function(data){
		                     //console.log(JSON.stringify(data));
		                    if(data.code==0){
		                    	mui.toast(data.msg);
		                        mui.back();
		                    }else{
		                    	mui.toast(data.msg);
		                    }
		                },
		                error:function(){
		                	mui.toast('注册失败，请重试！')
		    				return;
		                }
			    	})
			    }
		    })
			document.getElementById('logs').addEventListener('tap',function(){
				mui.openWindow({
					url:'login.html',
					id:'login.html'
				});
			});
		</script>
	</body>
</html>